package com.markus.code.剑指offer;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/2 17:29
 * todo: 数字序列中某一位的数字
 */
public class FindNthDigit {
    public int findNthDigit(int n) {
        //数的位数
        int digit = 1;
        //位数 刚开始的数字
        long start = 1;
        //位数的数字个数
        long count = 9;
        while(n > count){
            n -= count;
            digit += 1;
            start *= 10;
            count = digit * start * 9;
        }
        long num = start + (n-1) / digit;
        return Long.toString(num).charAt((n-1) % digit)-'0';
    }

    public static void main(String[] args) {
        int n = 1000000000;
        FindNthDigit demo = new FindNthDigit();
        System.out.println(demo.findNthDigit(n));
    }
}

